package com.grts.mall.controller;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.grts.mall.common.CommonResult;
import com.grts.mall.pojo.Admin;
import com.grts.mall.service.AdminService;

@Controller
public class LoginController {
	
	@Autowired
	private AdminService adminService;
	
	@RequestMapping("/login")
	public String login() {
		return "login";
	}
	
	@RequestMapping("/doLogin")
	@ResponseBody
	public CommonResult doLogin(Admin admin, HttpSession session) {
		boolean success = this.adminService.login(admin);
		if (success) {
			session.setAttribute("admin", admin);
			return CommonResult.success("登录成功", "/index");
		} else {
			return CommonResult.error("用户名或密码错误");
		}
	}
	
}
